// 1-对于数据请求的封装
// import axios from 'axios'
// function httpForDetial () {
//   return axios({
//     url: `https://m.maizuo.com/gateway?filmId=${this.$route.params.myid}&k=1483226`,
//     headers: {
//       'X-Client-Info': '{"a":"3000","ch":"1002","v":"5.2.1","e":"16633350532206255980478465","bc":"310100"}',
//       'X-Host': 'mall.film-ticket.film.info'
//     }
//   })
// }

// function httpForList () {
//   return axios({
//     url: 'https://m.maizuo.com/gateway?cityId=310100&pageNum=1&pageSize=10&type=1&k=698189',
//     headers: {
//       'X-Client-Info': '{"a":"3000","ch":"1002","v":"5.2.1","e":"16633350532206255980478465","bc":"310100"}',
//       'X-Host': 'mall.film-ticket.film.list'
//     }
//   })
// }

// export default {
//   httpForDetial,
//   httpForList

// }

// 2- 对于数据的请求封装
import { Toast } from 'vant'
import axios from 'axios'
const http = axios.create({
  baseURL: 'https://m.maizuo.com',
  timeout: 10000,
  headers: {
    'X-Client-Info': '{"a":"3000","ch":"1002","v":"5.2.1","e":"16633350532206255980478465","bc":"110100"}',
    'X-Host': 'mall.film-ticket.city.list'
  }
}
)
// 在发请求前拦截
http.interceptors.request.use(function (config) {
  // Do something before request is sent
  Toast.loading({
    message: '加载中...',
    forbidClick: true,
    duration: 0
  })
  return config
}, function (error) {
  // Do something with request error
  return Promise.reject(error)
})

// 在成功后拦截
// Add a response interceptor
http.interceptors.response.use(function (response) {
  // Any status code that lie within the range of 2xx cause this function to trigger
  // Do something with response data
  Toast.clear()

  return response
}, function (error) {
  // Any status codes that falls outside the range of 2xx cause this function to trigger
  // Do something with response error
  Toast.clear()
  return Promise.reject(error)
})
export default http
